﻿using BCCommon;
using BCDto.Common.NotificationMessageRecord;
using BCService.Common.NotificationMessageRecord;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.ClientApp.NotificationMessage
{
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [Route("api/v1/ClientApp/[controller]")]
    public class NotificationMessageRecordController : ClientAppBaseController
    {
        private readonly INotificationMessageRecordService notificationMessageRecordService;

        public NotificationMessageRecordController(INotificationMessageRecordService notificationMessageRecordService)
        {
            this.notificationMessageRecordService = notificationMessageRecordService;
        }

        #region 获取通知消息未读总数
        /// <summary>
        /// 获取通知消息未读总数
        /// </summary>
        /// <response code="200">通知消息未读总数</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(int), 200)]
        public IActionResult NoneReadCount()
        {
            var unreadCount = this.notificationMessageRecordService.GetUnreadCount(null, this.UserInfo);

            return this.Ok(unreadCount);
        }
        #endregion

        #region 获取通知消息记录(分页)
        /// <summary>
        /// 获取通知消息记录(分页)
        /// </summary>
        /// <param name="isRead">是否已读</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">订单信息</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<NotificationMessageRecordDto>), 200)]
        public IActionResult Get([FromQuery(Name = "is_read")]bool? isRead,
            [FromQuery(Name = "index")] int pageIndex = 1,
            [FromQuery(Name = "size")] int pageSize = 10)
        {
            var pageableList = this.notificationMessageRecordService.GetPageableList(null, this.UserInfo, isRead, null, pageIndex, pageSize);

            return this.Ok(pageableList);
        }

        #endregion

        #region 修改通知消息为已读
        /// <summary>
        /// 修改通知消息为已读
        /// </summary>
        /// <param name="notificationMessageId">通知消息Id</param>
        /// <response code="200">订单信息</response>
        /// <returns></returns>
        [HttpPut("{notification_message_id}")]
        [ProducesResponseType(typeof(NotificationMessageRecordDto), 200)]
        public IActionResult Put([FromRoute(Name = "notification_message_id")]long notificationMessageId)
        {
            return Ok(this.notificationMessageRecordService.UpdateReadStatus(notificationMessageId));
        }
        #endregion
    }
}
